package com.zhonghui.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhonghui.common.core.utils.RedisUtils;
import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.dto.CreateRechargeDto;
import com.zhonghui.dto.PageDto;
import com.zhonghui.mapper.RechargeMapper;
import com.zhonghui.service.RechargeService;
import com.zhonghui.vo.RechargeListVo;
import com.zhonghui.vo.RechargeRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: FL
 * @create: 2024 2024/5/17 10:15
 */
@Service
public class RechargeServiceImpl implements RechargeService {
    @Autowired
    RechargeMapper rechargeMapper;
    @Autowired
    RedisUtils redisUtils;
    @Override
    public FwResult getRecharge(PageDto pageDto) {
        PageHelper.startPage(pageDto.getCurrent(), pageDto.getSize());
        List<RechargeRecordVo> records = rechargeMapper.getRechargeRecord( pageDto);

        PageInfo<RechargeRecordVo> pageinfo = new PageInfo<>(records);
        RechargeListVo rechargeList = RechargeListVo.builder()
                .records(records)
                .total(pageinfo.getTotal())
                .size(pageDto.getSize())
                .current(pageDto.getCurrent())
                .pages(pageinfo.getPages())
                .searchCount(true)
                .build();
        return FwResult.ok(rechargeList);
    }

    @Override
    public FwResult createRechargeRecord(CreateRechargeDto createRechargeDto) {
        Integer i = rechargeMapper.createRechargeRecord(createRechargeDto);
        if (i == 1) {
            return FwResult.okMsg("充值成功");
        }
        return FwResult.failed();
    }


}
